<?php
/**
 * CreateUser: zlh
 * CreateTime: 2022/2/19 14:16
 * Remark:
 */

namespace App\Http\Controllers\Contract;

use App\Consts\ResponseConsts\ResponseStatusConsts;
use App\Func\ResponseFunc;
use App\Http\Controllers\Controller;
use App\Http\Requests\Contract\AddContractTempPost;
use App\Http\Requests\Contract\ListContractTempGet;
use App\Service\Contract\ContractTemplateService;

class ContractTemplateController extends Controller
{
    private ContractTemplateService $_contractTempService;

    public function __construct()
    {
        $this->middleware([
            'contractTempLeg'
        ]);
        $this->_contractTempService = new ContractTemplateService();
    }


    /**
     * @param AddContractTempPost $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function addContractTemplate(AddContractTempPost $request): \Illuminate\Http\JsonResponse
    {
        $data = $request->all();
        $res =  $this->_contractTempService->addContractTemplate($data);
        return ResponseFunc::returnJson(
            'ok',
            [
                "contract_template_id" =>$res
            ],
            '新增合同模板成功',
            ResponseStatusConsts::OK_200_RESPONSE_STATUS,
        );
    }


    /**
     * @param AddContractTempPost $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function addContractCurrentStaffTemplate(AddContractTempPost $request): \Illuminate\Http\JsonResponse
    {
        $data = $request->all();
        $res =  $this->_contractTempService->addContractCurrentStaffTemplate($data);
        return ResponseFunc::returnJson(
            'ok',
            [
                "contract_template_id" =>$res
            ],
            '新增我的合同模板成功',
            ResponseStatusConsts::OK_200_RESPONSE_STATUS,
        );
    }

    /**
     * 修改合同类型
     * @param int $contractTemplateId
     * @return \Illuminate\Http\JsonResponse
     */
    public function editContractTemplate(int $contractTemplateId): \Illuminate\Http\JsonResponse
    {
        $data = request()->post();
        $data['contract_template_id'] = $contractTemplateId;
        $this->_contractTempService->editContractTemplate($data);
        return ResponseFunc::returnJson(
            'ok',
            null,
            '修改合同模板成功',
            ResponseStatusConsts::OK_200_RESPONSE_STATUS,
        );
    }

    /**
     * 删除合同类型
     * @param int $contractTemplateId
     * @return \Illuminate\Http\JsonResponse
     */
    public function deleteContractTemplate(int $contractTemplateId): \Illuminate\Http\JsonResponse
    {
        $this->_contractTempService->deleteContractTemplate($contractTemplateId);
        return ResponseFunc::returnJson(
            'ok',
            null,
            '删除合同模板成功',
            ResponseStatusConsts::OK_200_RESPONSE_STATUS,
        );
    }

    /**
     * 获取合同详情
     * @param int $contractTemplateId
     * @return \Illuminate\Http\JsonResponse
     */
    public function getContractTemplateInfo(int $contractTemplateId): \Illuminate\Http\JsonResponse
    {
        return ResponseFunc::returnJson(
            'ok',
            $this->_contractTempService->getContractTemplateInfo($contractTemplateId),
            '获取合同模板详情成功',
            ResponseStatusConsts::OK_200_RESPONSE_STATUS,
        );
    }

    /**
     * 获取合同类型下拉
     * @return \Illuminate\Http\JsonResponse
     */
    public function getContractTemplateSelect(): \Illuminate\Http\JsonResponse
    {
        return ResponseFunc::returnJson(
            'ok',
            $this->_contractTempService->getContractTemplateSelect(),
            '获取合同模板下拉成功',
            ResponseStatusConsts::OK_200_RESPONSE_STATUS,
        );
    }

    public function getContractCurrentStaffTemplateSelect(): \Illuminate\Http\JsonResponse
    {
        return ResponseFunc::returnJson(
            'ok',
            $this->_contractTempService->getContractCurrentStaffTemplateSelect(),
            '获取合同模板下拉成功',
            ResponseStatusConsts::OK_200_RESPONSE_STATUS,
        );
    }

    /**
     * 获取合同模板列表
     * @param ListContractTempGet $request
     * @return mixed
     */
    public function getContractTemplateList(ListContractTempGet $request): mixed
    {
        $pageSize = $request->get('page_size');
        $filters = $request->get('filters');
        return ResponseFunc::returnJson(
            'ok',
            $this->_contractTempService->getContractTemplateList($pageSize,$filters),
            '获取合同模板列表成功',
            ResponseStatusConsts::OK_200_RESPONSE_STATUS
        );
    }

    /**
     * 获取我的合同模板列表
     * @param ListContractTempGet $request
     * @return mixed
     */
    public function getContractCurrentStaffTemplateList(ListContractTempGet $request): mixed
    {
        $pageSize = $request->get('page_size');
        $filters = $request->get('filters');
        return ResponseFunc::returnJson(
            'ok',
            $this->_contractTempService->getContractCurrentStaffTemplateList($pageSize,$filters),
            '获取合同模板列表成功',
            ResponseStatusConsts::OK_200_RESPONSE_STATUS
        );
    }
}